#!/usr/bin/python
# -*- coding: UTF-8 -*-

class Solution(object):
    """
    解法1：
        set集合计算差集
    """

    def missingNumber(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        origin = [i for i in range(len(nums)+1)]
        print(list(set(origin)-set(nums))[0])
        return list(set(origin)-set(nums))[0]

    """
    解法2：
        数字计算即可，计算出0～n的总和，减去nums的累加值即可
    """
    def missingNumber2(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        n = len(nums)
        print(n*(n+1)//2 - sum(nums))
        return n*(n+1)//2 - sum(nums)




nums = [3,0,1]
nums = [0,1]
# Solution().missingNumber(nums)

Solution().missingNumber2(nums)